/*
Date:20210515 20:45PM
key:1.相邻两个元素大小比较能决定前一个是+还是-
*/
class Solution {
public:

    int tra(char&c)
    {
        switch(c)
        {
            case 'I':return 1;
            case 'V':return 5;
            case 'X':return 10;
            case 'L':return 50;
            case 'C':return 100;
            case 'D':return 500;
            case 'M':return 1000;
        }
        return 0;
    }
    int romanToInt(string s) {
        
        int re=0;
        
        int i;
        for(i=1;i<s.size();i++)
        {
            if(tra(s[i-1])<tra(s[i])){re-=tra(s[i-1]);}
            else{re+=tra(s[i-1]);}
        }
        re+=tra(s[i-1]);
        return re;
    }
};